﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class SingletonMono<T> : MonoBehaviour where T : MonoBehaviour
{
    private static T _instance;
    public static T Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = GameObject.FindObjectOfType<T>();
                if (_instance == null)
                {
                    GameObject obj = new GameObject();
                    obj.name = typeof(T).Name;
                    _instance = obj.AddComponent<T>();
                    Object.DontDestroyOnLoad(obj);
                }
            }
            return _instance;
        }
    }

    public virtual void Awake()
    {
        var ins = Instance;
    }

    public virtual void Init()
    {

    }

    public virtual void OnDestory()
    {
        _instance = null;
    }

    public virtual void Clean()
    {

    }
}
